//
//  XDLMExpectView.m
//  xindailianmeng
//
//  Created by 于于 on 17/3/1.
//  Copyright © 2017年 xindailianmeng.cn. All rights reserved.
//

#import "XDLMExpectView.h"
#import "XDLMExpectTableViewCell.h"
@implementation XDLMExpectView
{
    NSArray *_dataArray;
    UITableView *_table;
    UILabel *_timeLabel;
    UILabel *_comeBack;
}
-(id)initWithFrame:(CGRect)frame data:(NSArray *)array
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setBackgroundColor:[UIColor clearColor]];
        _dataArray = array;
        [self creatView];
    }
    return self;
}

-(void)creatView
{
    UIView *bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
    [bgview setBackgroundColor:[UIColor grayColor]];
    [bgview setAlpha:0.5];
    [self addSubview:bgview];
    
    UIView *downBgView = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenH-229*kscale, kScreenW, kScreenH/3)];
    [self addSubview:downBgView];
    UILabel *label = [self createLabelWithFrame:CGRectMake(0, 0, kScreenW, 50*kscale) text:@"预计收益" textFont:[UIFont systemFontOfSize:16] textColor:kColorRGB(187, 147, 115)];
    [label setTextAlignment:NSTextAlignmentCenter];
    [label setBackgroundColor:kColorRGB(250, 250, 250)];
    label.userInteractionEnabled = YES;
    
    UIButton *dissmissBtn = [[UIButton alloc] initWithFrame:CGRectMake(kScreenW - 30*kscale, 17*kscale, 16*kscale, 16*kscale)];
    
    
    UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(0, 49.5*kscale, kScreenW, 0.5)];
    [line setBackgroundColor:kColorRGB(234, 234, 234)];
    [downBgView addSubview:label];
    [downBgView addSubview:line];
    
    [dissmissBtn setBackgroundImage:[UIImage imageNamed:@"Plus"] forState:UIControlStateNormal];
    [dissmissBtn addTarget:self action:@selector(dissmissBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [downBgView addSubview:dissmissBtn];
    [dissmissBtn bringSubviewToFront:downBgView];
    XDLMExpectTableViewCell *cell = [[XDLMExpectTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"1"];
    [cell setBackgroundColor:[UIColor whiteColor]];
    cell.frame = CGRectMake(0, 50*kscale, kScreenW, 40*kscale);
    cell.periods.text = @"期数";
    cell.collectionDate.text = @"收款日";
    cell.income.text = @"收益";
    UILabel *line1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 39.5*kscale, kScreenW, 0.5)];
    [line1 setBackgroundColor:kColorRGB(234, 234, 234)];
    [cell addSubview:line1];
    [downBgView addSubview:cell];
    
    _table = [[UITableView alloc] initWithFrame:CGRectMake(0, 90*kscale, kScreenW, downBgView.frame.size.height-130*kscale)];
    [_table setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_table setDelegate:self];
    [_table setShowsVerticalScrollIndicator:NO];
    [_table setDataSource:self];
    [downBgView addSubview:_table];
    
    _timeLabel = [self createLabelWithFrame:CGRectMake(0, downBgView.frame.size.height -40*kscale, kScreenW/2, 40*kscale) text:@"2017-3-40" textFont:[UIFont systemFontOfSize:14] textColor:kColorRGB(102,102 ,102 )];
    [_timeLabel setBackgroundColor:[UIColor whiteColor]];
    [_timeLabel setTextAlignment:NSTextAlignmentCenter];
    [downBgView addSubview:_timeLabel];
    
    _comeBack = [self createLabelWithFrame:CGRectMake(kScreenW/2, downBgView.frame.size.height -40*kscale, kScreenW/2, 40*kscale) text:@"反本: 100.00元" textFont:[UIFont systemFontOfSize:14] textColor:kColorRGB(51,51 ,51)];
    [_comeBack setBackgroundColor:[UIColor whiteColor]];
    [_comeBack setTextAlignment:NSTextAlignmentCenter];
    [downBgView addSubview:_comeBack];
    
    UILabel *line2 = [[UILabel alloc] initWithFrame:CGRectMake(15, downBgView.frame.size.height -40*kscale, kScreenW-30, 0.5)];
    [line2 setBackgroundColor:kColorRGB(234, 234, 234)];
    [downBgView addSubview:line2];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
    return _dataArray.count ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    XDLMExpectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"XDLMExpectTableViewCell"];
    if (!cell) {
        cell = [[XDLMExpectTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"XDLMExpectTableViewCell"];
    }
    cell.periods.text = @"第一期";
    cell.collectionDate.text = @"2017-12-30";
    cell.income.text = [_dataArray objectAtIndex:indexPath.row];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 33*kscale;
}
#pragma mark --点击方法
- (void)dissmissBtnClick
{
    [self removeFromSuperview];
}
#pragma mark --- 生成label
- (UILabel *)createLabelWithFrame:(CGRect)frame text:(NSString *)text textFont:(UIFont *)font textColor:(UIColor *)color {
    
    UILabel * label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.textColor = color;
    label.font = font;
    label.adjustsFontSizeToFitWidth = YES;
    label.textAlignment = NSTextAlignmentCenter;
    
    return label;
    
}
@end
